<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增维保维修工程水/电派工单项目')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-engineers-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">维修项目名称：</label>
                <div class="col-sm-8">
                    <input id="mMpname" name="mMpname" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">维修联系单/报价单上传：</label>
                <div class="col-sm-8">
                    <input id="mPriceSheet" name="file" class="form-control" type="file">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">维修项目状态：</label>
                <div class="col-sm-8">
                    <select id="mStatus" name="mStatus" th:with="type=${@dict.getType('maintenance_project_status')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}">
                    </select>
<!--                    <div class="radio-box">-->
<!--                        <input type="radio" name="mStatus" value="">-->
<!--                        <label th:for="mStatus" th:text="未知"></label>-->
<!--                    </div>-->
<!--                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>-->
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">维修发票/收据上传：</label>
                <div class="col-sm-8">
                    <input id="mReceipt" name="file1" class="form-control" type="file">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">维修费支付状态：</label>
                <div class="col-sm-8">
                    <select id="mCoststatus" name="mCoststatus" th:with="type=${@dict.getType('maintenance_coststatus')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}">
                    </select>
<!--                    <div class="radio-box">-->
<!--                        <input type="radio" name="mCoststatus" value="">-->
<!--                        <label th:for="mCoststatus" th:text="未知"></label>-->
<!--                    </div>-->
<!--                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>-->
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">水/电派工单上传：</label>
                <div class="col-sm-8">
                    <input id="mJobOrder" name="file2" class="form-control" type="file">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">创建时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input id="mDate" name="mDate" class="form-control" placeholder="yyyy-MM-dd" type="text">
                    </div>
                </div>
            </div>
            <div class="form-group" hidden>
                <label class="col-sm-3 control-label">外键id：</label>
                <div class="col-sm-8">
                    <input id="mtId" name="mtId" class="form-control" type="text" th:value="${mtId}">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">
        var prefix = ctx + "ruoyi/engineers"
        $("#form-engineers-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                // $.operate.save(prefix + "/add", $('#form-engineers-add').serialize());
                uploadFile();
            }
        }

        function uploadFile() {
            var formData = new FormData();
            if($('#mPriceSheet')[0].files[0] == null&&$('#mReceipt')[0].files[0] == null&&$('#mJobOrder')[0].files[0] == null) {
                $.modal.alertWarning("请先选择文件路径");
                return false;
            }else if($('#mPriceSheet')[0].files[0] != null&&$('#mReceipt')[0].files[0] != null&&$('#mJobOrder')[0].files[0] != null){
                formData.append('mMpname', $("#mMpname").val());
                formData.append('file', $('#mPriceSheet')[0].files[0]);
                formData.append('mStatus', $("#mStatus").val());
                formData.append('file1', $('#mReceipt')[0].files[0]);
                formData.append('mCoststatus', $("#mCoststatus").val());
                formData.append('file2', $('#mJobOrder')[0].files[0]);
                formData.append('mDate', $("#mDate").val());
                formData.append('mtId', $("#mtId").val());
                $.ajax({
                    url: prefix + "/add",
                    type: 'post',
                    cache: false,
                    data: formData,
                    processData: false,
                    contentType: false,
                    dataType: "json",
                    success: function(result) {
                        $.operate.successCallback(result);
                    }
                });
            }else if($('#mPriceSheet')[0].files[0] != null&&$('#mReceipt')[0].files[0] == null&&$('#mJobOrder')[0].files[0] == null){
                formData.append('mMpname', $("#mMpname").val());
                formData.append('file', $('#mPriceSheet')[0].files[0]);
                formData.append('mStatus', $("#mStatus").val());
                formData.append('mCoststatus', $("#mCoststatus").val());
                formData.append('mDate', $("#mDate").val());
                formData.append('mtId', $("#mtId").val());
                $.ajax({
                    url: prefix + "/addone",
                    type: 'post',
                    cache: false,
                    data: formData,
                    processData: false,
                    contentType: false,
                    dataType: "json",
                    success: function(result) {
                        $.operate.successCallback(result);
                    }
                });
            }else if($('#mPriceSheet')[0].files[0] == null&&$('#mReceipt')[0].files[0] != null&&$('#mJobOrder')[0].files[0] == null){
                formData.append('mMpname', $("#mMpname").val());
                formData.append('mStatus', $("#mStatus").val());
                formData.append('file1', $('#mReceipt')[0].files[0]);
                formData.append('mCoststatus', $("#mCoststatus").val());
                formData.append('mDate', $("#mDate").val());
                formData.append('mtId', $("#mtId").val());
                $.ajax({
                    url: prefix + "/addtwo",
                    type: 'post',
                    cache: false,
                    data: formData,
                    processData: false,
                    contentType: false,
                    dataType: "json",
                    success: function(result) {
                        $.operate.successCallback(result);
                    }
                });
            }else if($('#mPriceSheet')[0].files[0] == null&&$('#mReceipt')[0].files[0] == null&&$('#mJobOrder')[0].files[0] != null){
                formData.append('mMpname', $("#mMpname").val());
                formData.append('mStatus', $("#mStatus").val());
                formData.append('mCoststatus', $("#mCoststatus").val());
                formData.append('file2', $('#mJobOrder')[0].files[0]);
                formData.append('mDate', $("#mDate").val());
                formData.append('mtId', $("#mtId").val());
                $.ajax({
                    url: prefix + "/addthree",
                    type: 'post',
                    cache: false,
                    data: formData,
                    processData: false,
                    contentType: false,
                    dataType: "json",
                    success: function(result) {
                        $.operate.successCallback(result);
                    }
                });
            }else if($('#mPriceSheet')[0].files[0] == null&&$('#mReceipt')[0].files[0] != null&&$('#mJobOrder')[0].files[0] != null){
                formData.append('mMpname', $("#mMpname").val());
                formData.append('mStatus', $("#mStatus").val());
                formData.append('file1', $('#mReceipt')[0].files[0]);
                formData.append('mCoststatus', $("#mCoststatus").val());
                formData.append('file2', $('#mJobOrder')[0].files[0]);
                formData.append('mDate', $("#mDate").val());
                formData.append('mtId', $("#mtId").val());
                $.ajax({
                    url: prefix + "/addfour",
                    type: 'post',
                    cache: false,
                    data: formData,
                    processData: false,
                    contentType: false,
                    dataType: "json",
                    success: function(result) {
                        $.operate.successCallback(result);
                    }
                });
            }else if($('#mPriceSheet')[0].files[0] != null&&$('#mReceipt')[0].files[0] == null&&$('#mJobOrder')[0].files[0] != null){
                formData.append('mMpname', $("#mMpname").val());
                formData.append('file', $('#mPriceSheet')[0].files[0]);
                formData.append('mStatus', $("#mStatus").val());
                formData.append('mCoststatus', $("#mCoststatus").val());
                formData.append('file2', $('#mJobOrder')[0].files[0]);
                formData.append('mDate', $("#mDate").val());
                formData.append('mtId', $("#mtId").val());
                $.ajax({
                    url: prefix + "/addfive",
                    type: 'post',
                    cache: false,
                    data: formData,
                    processData: false,
                    contentType: false,
                    dataType: "json",
                    success: function(result) {
                        $.operate.successCallback(result);
                    }
                });
            }else if($('#mPriceSheet')[0].files[0] != null&&$('#mReceipt')[0].files[0] != null&&$('#mJobOrder')[0].files[0] == null){
                formData.append('mMpname', $("#mMpname").val());
                formData.append('file', $('#mPriceSheet')[0].files[0]);
                formData.append('mStatus', $("#mStatus").val());
                formData.append('file1', $('#mReceipt')[0].files[0]);
                formData.append('mCoststatus', $("#mCoststatus").val());
                formData.append('mDate', $("#mDate").val());
                formData.append('mtId', $("#mtId").val());
                $.ajax({
                    url: prefix + "/addsix",
                    type: 'post',
                    cache: false,
                    data: formData,
                    processData: false,
                    contentType: false,
                    dataType: "json",
                    success: function(result) {
                        $.operate.successCallback(result);
                    }
                });
            }

        }
        $("input[name='mDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>
</html>